﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.LazyConcurrentDictionary`2
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Threading;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal class LazyConcurrentDictionary<TKey, TValue>
  {
    private readonly ConcurrentDictionary<TKey, Lazy<TValue>> concurrentDictionary;

    public LazyConcurrentDictionary()
    {
      this.concurrentDictionary = new ConcurrentDictionary<TKey, Lazy<TValue>>();
    }

    public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
    {
      return this.concurrentDictionary.GetOrAdd(key, (Func<TKey, Lazy<TValue>>) (k => new Lazy<TValue>((Func<TValue>) (() => valueFactory(k)), LazyThreadSafetyMode.ExecutionAndPublication))).Value;
    }

    public bool ContainsUninitializedValue(TKey key)
    {
      Lazy<TValue> lazy;
      return this.concurrentDictionary.TryGetValue(key, out lazy) && !lazy.IsValueCreated;
    }

    public void Remove(TKey key) => this.concurrentDictionary.TryRemove(key, out Lazy<TValue> _);
  }
}
